package io.renren.api.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;

import io.renren.api.dao.BtCustomerNavbarDao;
import io.renren.api.entity.BtCustomerNavbarEntity;
import io.renren.api.service.BtCustomerNavbarService;
import io.renren.utils.Query;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;


@Service("btCustomerNavbarService")
public class BtCustomerNavbarServiceImpl extends ServiceImpl<BtCustomerNavbarDao, BtCustomerNavbarEntity> implements BtCustomerNavbarService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<BtCustomerNavbarEntity> page = this.selectPage(
                new Query<BtCustomerNavbarEntity>(params).getPage(),
                new EntityWrapper<BtCustomerNavbarEntity>()
        );

        return new PageUtils(page);
    }
    @Override
    public List<BtCustomerNavbarEntity> queryList(Map<String, Object> params){
        Long cust_id = (Long) params.get("cust_id");
        List<BtCustomerNavbarEntity> deptList =
                this.selectList(new EntityWrapper<BtCustomerNavbarEntity>().eq("cust_id",cust_id));

        for(BtCustomerNavbarEntity sysDeptEntity : deptList){
            BtCustomerNavbarEntity parentDeptEntity =  this.selectById(sysDeptEntity.getPid());
            if(parentDeptEntity != null){
                sysDeptEntity.setParentName(parentDeptEntity.getName());
            }
        }
        return deptList;
    }
   public List<Long> queryNavBarIdList(Long pid){
        return baseMapper.queryNavBarIdList(pid);
    }
    @Transactional
    public Long insertOneBackprimkey(BtCustomerNavbarEntity entity){

       return baseMapper.insertOneBackprimkey(entity);
    }
}
